/*
 *  创建应用的根 Widget
 *  1. 创建一个简单的路由，并注册页面
 *  2. 对所需的页面进行和 AppStore 的连接
 *  3. 对所需的页面进行 AOP 的增强
 */

import 'package:flutter/material.dart' hide Action, Page;
import 'loginPage.dart';
import 'app_route.dart';///<全局路由
import 'package:app_happy_flutter/code/Tool/animationPageRoute.dart';
Widget createApp() {

  return MaterialApp(
    title: 'FishDemo',
    theme: ThemeData(
      primarySwatch: Colors.blue,
    ),
    //主页面
    home: LoginPage(),
    onGenerateRoute: _onGenerateRoute,
//    onGenerateRoute: (RouteSettings settings) {
//      return MaterialPageRoute<Object>(builder: (BuildContext context) {
//        return AppRoute.global.buildPage(settings.name, settings.arguments);
//      });
//    },
  );
}

Route<dynamic> _onGenerateRoute(settings) {

  WidgetBuilder builder;

  String name = settings.name.toString();
  if (name.startsWith(RoutePath.Base)) {
    print("==路由名称以${RoutePath.Base}开头===${settings.name}");
    builder = (_) => AppRoute.global.buildPage(settings.name, settings.arguments);
  }else {
    builder = (_) => LoginPage();
    print("==路由名称===${settings.name}");
  }
  return AnimationPageRoute(
      builder: builder,
      animationType: AnimationType.SlideTopToBottom,
      pageAffectedType: PageAffectedType.Both);

}
